home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10447 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: nntp-trd.UNINETT.no!usenet
  2. From: Paul Kenneth Egell-johnsen <paulken4@afrodite.kih.no>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Template declaration in h file and cpp fil
  5. Date: Thu, 07 Mar 1996 09:18:13 +0100
  6. Organization: UNINETT news service    
  7. Message-ID: <313E9BC5.2DF2@afrodite.kih.no>
  8. References: <4hhafd$f8d@academy.bastad.se> <Pine.SOL.3.91.960305172908.17346D-100000@hamlet.uncg.edu>
  9. NNTP-Posting-Host: afrodite.kih.no
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-1
  12. Content-Transfer-Encoding: quoted-printable
  13. X-Mailer: Mozilla 2.0 (X11; I; HP-UX A.09.05 9000/720)
  14.  
  15. QIAN . ZHONG wrote:
  16. > =
  17.  
  18. > =
  19.  
  20. > =
  21.  
  22. > On Tue, 5 Mar 1996, Mikael Bergqvist wrote:
  23. > =
  24.  
  25. > > Hi!
  26. > >
  27. > > I=B4m having a problem with the following code:
  28. > >
  29. > > SORT.H:
  30. > >
  31. > > template <class TArray>
  32. > > void QSort(int lo,int hi,TArray *array);
  33. > >
  34. > > END SORT.H
  35. > >
  36. > > SORT.CPP
  37. > > #include "sort.h"
  38. > > template <class TArray>
  39. > > void QSort(int lo,int hi,TArray *array)
  40. > > {
  41. > >
  42. > > ..... some code
  43. > > }
  44. > >
  45. > > END SORT.CPP
  46. > >
  47. > > TEST.CPP
  48. > >
  49. > > #include "sort.h"
  50. > >
  51. > > int main(void)
  52. > > {
  53. > >       int array[10]=3D{.........};
  54. > >       QSort(0,9,array);
  55. > > }
  56. > >
  57. > > END TEST.CPP
  58. > >
  59. > > The problem is that the linker returns the following error:
  60. > > Undefinded symbol QSort(int,int,int far *); in module test.cpp
  61. > >
  62. > > This problem doesent occur if the main function is in SORT.CPP below
  63. > > the QSort function.
  64. > >
  65. > > HELP!
  66. > >
  67. > > /Mikael
  68. > >
  69. > =
  70.  
  71. >  You should put SORT.CPP into SORT.H and include SORT.H into
  72. > every .CPP files.
  73. > =
  74.  
  75. No! You should make a makefile, perhaps a SORT library
  76. (precompile the class). It is easier to put SORT.CPP inn i
  77. SORT.H, I'll grant you that, but it is contrary to the intents
  78. of headerfiles and implementationfiles.
  79.  
  80. And if you are going to reuse your classes, you would like to
  81. precompile them, in order to just linking them into your code
  82. later.
  83.  
  84. Sorry, no help on that subject from me, I just tried it out
  85. until i found a good solution, but I can say this:
  86.  
  87.     On unix use mkmf to make a makefile. Then go into the file and
  88. look for obvious mistakes, or paths which are missing or wrong.
  89. When you have done your enhancements, you may use mkmf each time
  90. you add a new .h or .cpp file, and the EARLIER changes you have
  91. done will not be void!
  92.     In larger packages (Visual C++, Borland and such) there should
  93. be some sort of projectmanagement which will help you out.
  94.     On other systems, try the unix way (on Mac, the package way).
  95. On the Amiga SAS/C the mkmf program is called makemf.
  96.  
  97. After makinkg a makefile, just type make in the apropriate
  98. directory, and your program should compile!
  99.  
  100. Paul K Egell-Johnsen,
  101.  
  102. mailto:paulken4@afrodite.kih.no
  103. http://afrodite.kih.no:8001/studenter/paulken4/frames/
  104.